<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<base th:href="@{/}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<th:block th:include ="commHeaderInclude::commHead"></th:block>
<title>填写融资申请</title>
<style>
	.form{}
	.form .error{ color: #f30; margin-left: 20px; display: none;}
	.form .tips{margin-left: 5px;}
	
</style>
<script type="text/javascript" th:src="@{common/uploader/uploader.js}"></script>
<link th:href="@{common/uploader/uploader.css}" rel="stylesheet" type="text/css">
</head>
<body class="ht">
<th:block th:include="commHeaderInclude::loading"></th:block>
	<div class="tabTitle"><span><i class="mdi mdi-menu-up"></i>申请融资</span></div>
	<div class="content-wrapper">
		<div class="breadCrumb">
			<i class="mdi mdi-map-marker"></i>
			<span><span th:text="${session.mcpName}"></span><i class="mdi mdi-chevron-double-right"></i>融资服务<i class="mdi mdi-chevron-double-right"></i>申请融资</span>
		</div>
		<form name="form" id="form" class="form" method="post" th:object="${dto}">
			<input type="hidden" name="token" th:value="${session.token}">
			<div class="card mb-3">
				<div class="card-body">
					<h4 class="card-title">
						<span>金融产品信息</span>
						<a id="productSelectorBtn" class="btn btn-primary btn-sm" href="hos/finance/productSelector" role="openFrameWindow">选择</a>
					</h4>
					<div class="alert alert-warning"><i class=" mdi mdi-alert-circle"></i>该业务仅支持向一家资金方申请融资；终止已有融资关系后，可变更资金方或金融产品。</div>
					<div class="module">
						<table cellpadding="0" cellspacing="0" class="hTable">
							<thead>
								<tr>
									<th>序号</th>
									<th>产品名称</th>
									<th>资金方</th>
									<th>适用区域</th>
									<th>发布时间</th>
									<th>贷款金额（万元）</th>
									<th>贷款期限（月）</th>
									<th>参考利率</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td name="rowId"></td>
									<td name="productName"></td>
									<td><a name="bankOrgName" class="textLink-primary" role="openFrameWindow"></a></td>
									<td name="areaNames"></td>
									<td name="publishTimeStr" class="time" ></td>
									<td name="amount" class="amount" ></td>
									<td name="timeLimit"></td>
									<td name="rate"></td>
								</tr>
							</tbody>
							<input type="hidden" name="productId" value="" />
							<input type="hidden" name="bankOrgId" value="" />
						</table>
					</div>
				</div>
			</div>

			<div class="card mb-3">
				<div class="card-body">
					<h4 class="card-title">融资申请信息</h4>
					<div class="module">
						<table cellpadding="0" cellspacing="0" class="vTable">
							<tbody>
                                <tr>
                                    <th class="label">医保统筹区</th>
                                    <td>
<!--                                    	<div role="SelectGroup" data-options="url:'/mcp/base/area/',defaultText:'请选择'">-->
<!--											<select name="province">-->
<!--												<option th:value="*{province}" class="selected" selected></option>-->
<!--											</select>-->
<!--											<select name="city" style="width: auto">-->
<!--												<option th:value="*{city}" class="selected" selected></option>-->
<!--											</select>-->
<!--											<select name="county" style="width: auto">-->
<!--												<option th:value="*{county}" class="selected" selected></option>-->
<!--											</select>-->
<!--											<span class="error" th:errors="*{province}" th:if="*{#fields.hasErrors('province')}"></span>-->
<!--											<span class="ml-1 tips">同一统筹区不支持向多家资金方提交融资申请</span>-->
<!--										</div>-->


										<input type="hidden" id="pfmId" name="pfmId" th:value="*{pfmId}" />
										<input type="text" id="pfmAreaAddress" name="pfmAreaAddress" th:value="*{pfmAreaAddress}" disabled style="background-color: #eee; color:#999;" />
                                    </td>
                                </tr>
								<tr>
									<th class="label">定点机构类型</th>
									<td><input type="text" name="miOrgType" th:value="*{miOrgType}" maxlength="50" /><span class="error" th:errors="*{miOrgType}" th:if="*{#fields.hasErrors('miOrgType')}"></span></td>
								</tr>
								<tr>
									<th class="label">申请金额</th>
									<td><input type="amount" id="financeAmount" name="financeAmount" th:value="*{financeAmount}" />
										<span class="error" th:errors="*{financeAmount}" th:if="*{#fields.hasErrors('financeAmount')}"></span>
									</td>
								</tr>
								<tr>
									<th class="label">申请币种</th>
									<td>人民币元</td>
								</tr>
								<tr>
									<th class="label">融资期限</th>
									<td>
										<select id="financeLimit" name="financeLimit" > 
								            <option value="">请选择</option>
								            <option value="1" th:selected="*{financeLimit == '1'}">1-3月</option>
								            <option value="2" th:selected="*{financeLimit == '2'}">4-6月</option>
								            <option value="3" th:selected="*{financeLimit == '3'}">7-9月</option>
								            <option value="4" th:selected="*{financeLimit == '4'}">10-12月</option>
								            <option value="5" th:selected="*{financeLimit == '5'}">13-24月</option>
								            <option value="6" th:selected="*{financeLimit == '6'}">25-36月</option>
								            <option value="7" th:selected="*{financeLimit == '7'}">36月以上</option>
								        </select >
										<span class="error" th:errors="*{financeLimit}" th:if="*{#fields.hasErrors('financeLimit')}"></span>
									</td>
								</tr>
								<tr>
									<th class="label">借款用途</th>
									<td><textarea name="financePurpose" th:text="*{financePurpose}" maxlength="500"></textarea><span class="error" th:errors="*{financePurpose}" th:if="*{#fields.hasErrors('financePurpose')}"></span><span class="ml-1 tips">不超过500位</span></td>
								</tr>
                                <tr>
                                    <th class="label">主体信息表</th>
                                    <td><a class="textLink-primary" role="openFrameWindow"  th:href="@{'base/hospital/detail1'}" >主体信息表</a><span class="tips">（提示：信息由相关主管机构共享及更新，请确认是否准确，如有异议，请在下方备注栏说明。）</span></td>
                                </tr>
                                <tr>
                                    <th><b>医保结算账户信息</b></th>
                                    <td></td>
                                </tr>
								<tr>
									<th class="label">开户名称</th>
									<td><input type="text" name="accountName" th:value="*{accountName}" maxlength="200" /><span class="error" th:errors="*{accountName}" th:if="*{#fields.hasErrors('accountName')}"></span><span class="ml-1 tips">长度不能超过200位</span></td>
								</tr>
								<tr>
									<th class="label">银行账号</th>
									<td><input type="text" name="accountNo" th:value="*{accountNo}" maxlength="50" /><span class="error" th:errors="*{accountNo}" th:if="*{#fields.hasErrors('accountNo')}"></span><span class="ml-1 tips">长度不能超过50位</span></td>
								</tr>
								<tr>
									<th class="label">开户行</th>
									<td><input type="text" name="accountBank" th:value="*{accountBank}" maxlength="200" /><span class="error" th:errors="*{accountBank}" th:if="*{#fields.hasErrors('accountBank')}"></span><span class="ml-1 tips">长度不能超过200位</span></td>
								</tr>
								<tr>
									<th class="label">联系人</th>
									<td><input type="text" name="contactName" th:value="*{contactName}" maxlength="20" /><span class="error" th:errors="*{contactName}" th:if="*{#fields.hasErrors('contactName')}"></span><span class="ml-1 tips">联系人输入长度不能超过20位</span></td>
								</tr>
								<tr>
									<th class="label">移动电话</th>
									<td><input type="mobile" name="contactMobile" th:value="*{contactMobile}" maxlength="11" /><span class="error" th:errors="*{contactMobile}" th:if="*{#fields.hasErrors('contactMobile')}"></span><span class="ml-1 tips">仅业务变动提醒，短信服务免费</span></td>
								</tr>
								<tr>
									<th>固定电话</th>
									<td><input type="text" name="contactTel" th:value="*{contactTel}" maxlength="20" /><span class="ml-1 tips">输入的固定号码不能超过20位</span></td>
								</tr>
								<tr>
									<th>备注</th>
									<td><textarea name="financeRemark" th:text="*{financeRemark}" maxlength="500" ></textarea><span class="ml-1 tips">长度不能超过500位</span></td>
								</tr>
                                <!-- tr>
                                    <th>附件</th>
                                    <td><textarea name="attachFileContent" class="limited" th:value="*{attachFileContent}"></textarea>
									<script>
                                        var options={
                                            action:"/mcp/uploader2/upload/",
                                            type:".jpg,.jpeg,.png,.pdf,.rar,.zip",
                                            ext:".jpg,.jpeg,.png,.pdf,.rar,.zip"
                                        }
                                        var uploader = new Uploader('[name=attachFileContent]', options)
									</script></td>
                                </tr -->

                                <tr>
                                    <th><span class="required">*</span>签发授权</th>
                                    <td>
                                        <p><span class="mr-1">授权起始日</span><input disabled="disabled" class="ht-dateInput" type="date" name="authStartTime" th:value="*{authStartTime}" placeholder="" data-options="endSelector:'[name=authEndTime]'" style="background-color: #eee; color:#999;" /></p>
                                        <p><span class="mr-1">授权截止日</span><input class="ht-dateInput" type="date" name="authEndTime" th:value="*{authEndTime}" placeholder="" data-options="startSelector:'[name=authStartTime]'" style="background-color: #fff;"/></p>
                                        <p><span class="mr-1">授权书编号</span><a name="authDetail" th:href="@{'base/auth/detail?id='+*{authId}+'&aid='+*{authAid}}" class="textLink-primary" role="openFrameWindow"  th:text="*{authNo}" >授权书</a><input type="hidden" name="authNo" th:value="*{authNo}" /><input type="hidden" name="authId" th:value="*{authId}" /><span class="error" th:errors="*{authNo}" th:if="*{#fields.hasErrors('authNo')}"></span></p>
                                        <p>
                                        	<a id="signAuth" class="btn btn-outline-primary btn-sm" >签发授权书</a>
                                        </p>
                                    </td>
                                </tr>
                                <tr>
                                    <th><span class="required">*</span>业务规则</th>
                                    <td>
                                        <p>
											<input name="guize1" th:checked="*{guize1}" type="checkbox" />
											<span class="ml-1">我知悉并同意授权资金方通过中征应收账款融资服务平台查询我方主体信息、医保结算信息等。</span>
										</p>
                                        <p>
											<input name="guize2" th:checked="*{guize2}" type="checkbox" />
											<span class="ml-1">我已认真阅读并同意<a class="textLink-primary" role="openFrameWindow" href="hos/finance/businessRules">《应收账款融资服务平台医惠贷业务规则》</a>。</span>
										</p>
                                    </td>
                                </tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>

			<div class="row">
				<input class="btn btn-primary btn-lg" type="submit" value="提 交" />
			</div>
		</form>
	</div>
	
	
	<div class="ht-dialog auto" role="autoOpenDialog">
	<div class="wrapper">
		<h4 class="title" th:text="${result.msg}">提示</h4>
		<a class="ht-closeButton">close</a>
		<div class="content">
			<ul th:if="${#fields.hasErrors('dto.*')}">
				<li th:each="err:${#fields.errors('dto.*')}"  th:utext="${err}"></li>
			</ul>
		</div>
	</div>
</div>
</body>
<script>
$(function(){
	var productId = '[[${dto.productId}]]';
	if(productId != null && productId != ""){
		setProductById(productId);
	}
	
	var authNo = '[[${dto.authNo}]]';
	if(authNo != null && authNo != ""){
		$("#signAuth").hide();
		$("#productSelectorBtn").hide();
		$("[name='authEndTime']").attr("disabled","disabled");
	}
});

function setProductById(id){
    loadProductById(id);
}
function loadProductById(id){
    var options={
        url:baseUrl+"/hos/finance/productDetail/?id="+id,
        success(res){
            console.log(res);
            var data = res.data;
            
            $("[name=productId]").val(data.id);
            $("[name=bankOrgId]").val(data.bankOrgId);
            
            $("[name='rowId']").text(1);
            $("[name=productName]").text(data.productName);
            $("[name=bankOrgName]").text(data.bankOrgName);
            $("[name=bankOrgName]").attr('href','base/bank/detail?id='+data.bankOrgId);
            $("[name=areaNames]").text(data.areaNames);
            $("[name=publishTimeStr]").text(data.publishTimeStr);
            $("[name=amount]").text(data.amount);
            $("[name=timeLimit]").text(data.timeLimit);
            $("[name=rate]").text(data.rate);
            
            ht.closeAllFrameWindow();
        },
        fail(err){
            console.log(err);
        }
    };
    $.ajax(options)
}


$("#signAuth").on("click",function(event){
	var authStartTime = $("[name='authStartTime']").val();
	var authEndTime = $("[name='authEndTime']").val();
	var bankOrgId = $("[name='bankOrgId']").val();
	
	console.log(authStartTime+authEndTime+bankOrgId);
	
	var beginDate = new Date(authStartTime);
	var endDate = new Date(authEndTime);
	
	console.log(beginDate);
	console.log(endDate);
	
	if(authStartTime == "" || authEndTime == ""){
		alert('请录入授权起止日期');
		return false;
	}else if(beginDate > endDate){
		alert('授权到期日不得小于授权起始日');
		return false;
	}else if(bankOrgId == ""){
		alert('请先选择金融产品信息');
		return false;
	}else{
		ht.openFrameWindow(baseUrl+'/hos/auth/create?authStartTime='+authStartTime+"&authEndTime="+authEndTime+"&bankOrgId="+bankOrgId,"","fullScreen");
	}
	
})

$("#form").on("submit",function(){
	ht.loading.open();
	
	var productId = $("[name='productId']").val();
	var authId = $("[name='authId']").val();
	var guize1 = $("[name='guize1']").is(':checked');
	var guize2 = $("[name='guize2']").is(':checked');
	
	if(productId == ""){
		alert('请先选择金融产品信息');
		ht.loading.close();
		return false;
	}else if(authId == ""){
		alert('请签发授权书');
		ht.loading.close();
		return false;
	}else if(!guize1 || !guize2){
		alert('请确认业务规则已知悉');
		ht.loading.close();
		return false;
	}
	
	return true;
});

function setAuthInfo(authNo, authId, authAid){
	$("[name='authNo']").val(authNo);
	$("[name='authId']").val(authId);
	$("[name='authDetail']").attr("href","base/auth/detail?id="+authId+"&aid="+authAid);
	$("[name='authDetail']").text(authNo);
	$("#signAuth").hide();
	$("#productSelectorBtn").hide();
	$("[name='authEndTime']").attr("disabled","disabled");
	alert("授权书签发成功，请您继续完成融资申请流程");
	
	ht.closeAllFrameWindow();
}


var ruleParser=new RuleParser("#form");
ruleParser.loadRule(baseUrl+"/hos/finance/createFormRule.json")
</script>
</html>